package com.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dao.PostDao;
import com.model.Post;
import com.model.UsersCompany;
import com.service.PostService;
import com.service.UsersCompanyService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 公司岗位表 前端控制器
 * </p>
 *
 * @author Damon
 * @since 2021-05-06
 */
@RestController
@RequestMapping("/post")
public class PostController {
    @Autowired(required = false)
    private PostService postService;

    //职位列表
        @RequestMapping("/list")
        public List<Post> testPage(Long pageNum, Long size,String key){
            Page<Post> page = new Page<>(pageNum,size);
            postService.listPage(page,new Post(key));
            return page.getRecords();
        }




    @RequestMapping("/listAll")
    public List<Post> listAll(){
        List<Post> list = postService.list();
        return list;
    }

    @RequestMapping("/list1")
    public Page<Post> list(String enameS, Long pageNum, Long size){
        Page<Post> page = new Page<>(pageNum, size);
        page = postService.listPage(page,new Post("0",enameS));
        return page;
    }

    @RequestMapping("/del")
    public Boolean del(Post post){
        return postService.removeById(post.getId());
    }

    @RequestMapping("/add")
    public Boolean edit(@RequestBody Post post){
        Boolean res=false;
        if ("1".equals(post.getModify())){
            res=postService.save(post);
        }else {
            res=postService.updateById(post);
        }
        return res;
    }
    @RequestMapping("/getpostbyid")
    public Post getbyid(int id){
        return postService.getById(id);
    }
}

